<extend name="common:base" />
<block name="content">
    <div id="header">
        <div class="header">
            <h1 class="tit">收货地址</h1>
            <p class="goback">
                <a class="return" href="{:U('Setting/index')}">返回</a>
            </p>
            <p class="more"><a class="share" href=""></a></p>
        </div>
    </div>

    <div class="shdz-zong">
        <foreach name="address" item="inv">
			<div class="shdz-a">
				<p class="shdz-p1"><a>{$inv['consignee']}</a><a class="a-right">{$inv['mobile']}</a></p>
				<p class="shdz-p2">{$inv['province']} {$inv['city']} {$inv['area']}  {$inv['detail_address']}</p>
				<div class="shdz-aa">
					<div class="shdz-left">
                        <if condition="$inv['is_default'] eq 1">
                            <input type="radio" class="set_default bg-color" for="{$inv['address_id']}"/><span>设为默认</span>
                        <else/>
                            <input type="radio" class="set_default" for="{$inv['address_id']}"/><span>设为默认</span>
                        </if>
					</div>
					<div class="shdz-right">
						<a href="{:U('Setting/edit_address', array('id' => $inv['address_id']))}"><img src="{:C('__STATIC__')}{$theme}/Static/img/address.jpg"><span>编辑</span></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
						<a for="{$inv['address_id']}" class="del_address"><img src="{:C('__STATIC__')}{$theme}/Static/img/delete.jpg"><span>删除</span></a>
					</div>
				</div>
			</div>
        </foreach>
    </div>

    <a class="add-address" href="{:U('Setting/address_add')}">新增收货地址</a>
</block>
<block name="CSS">
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/total.css" />
    <style>
        body {background: #f7f7fa;}
    </style>
</block>
<block name="JS">
    <script type="text/javascript">
        $(function() {




            //设为默认收货地址
            $(".shdz-left input").click(function(){
                $(this).addClass("bg-color").parents(".shdz-a").siblings().find("input").removeClass("bg-color");
            });


            //删除默认收货地址
            $('.del_address').click(function(){
                var ad_id = $(this).attr("for");
                layer.confirm('您确认删除此地址吗？', {
                    btn: ['是的','取消'] //按钮
                }, function(){
                    $.ajax({
                        url:"{:U('Setting/address_del')}",
                        type: 'post',
                        data:{address_id: ad_id},
                        success:function (data) {
                            if(data){
                                if(data.status == "success"){
                                    location.reload(true);
                                }else{
                                    layer.msg(data.msg ,{icon:2,time:1000});
                                }
                            }else{
                                layer.msg("删除失败" ,{time:800});
                            }
                        }
                    });
                });
            });


            //设置为默认收货地址
            $('.set_default').click(function() {
                var ad_id = $(this).attr("for");
                $.ajax({
                    url:"{:U('Setting/change_default')}",
                    type: 'post',
                    data:{address_id: ad_id},
                    success:function (data) {
                        if(data.status == "success"){
                            layer.msg("切换成功" ,{icon:1,time:500});
                        }else{
                            layer.msg(data.msg ,{icon:2,time:1000});
                        }
                    }
                });
            });
        });
    </script>
</block>